home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-03 | 2.5 KB | 74 lines | [TEXT/OIUB] |
- `timescale 1 ns / 100 ps
- /* Linear Feedback Shift Register
- * verilog module "LFSR"
- * Generated by Macintosh application 'LFSR' 5/17/93 1:55 PM
- * company: Apple Computer
- * project: Display Controller
- * designer: Elmer Fudd
- * prototypes:
- LFSR(clk, preset, TC);
- LFSR(.clk(CLOCK), .preset(PRESET), .TC(TC));
- *
- * The counter reaches terminal count after 2000000 positive edge clocks.
- * 'TC' is asserted high at the end of count.
- * count is preset synchronously by an active high on 'preset'.
- * The counter stops after terminal count and must be preset to count again.
- * The counter uses small auxiliary counter to detect for terminal count by counting all 'ones' being
- * shifted into the main counter. The preset of the small auxiliary counter is connected to the
- * input of the main shift register and terminal count is generated only when 23 '1' bits have shifted into the main counter.
- * The auxiliary counter is 5 registers with two taps feedback to the input.
- * The main counter consist of 23 registers with 2 taps feedback to the input.
- */
- module LFSR (clk, preset, TC);
- input clk;
- input preset;
- output TC;
- reg [22:0] D;
- reg [22:0] Q;
- wire isCounting;
- reg [4:0] AUX_D;
- reg [4:0] AUX_Q;
-
- assign TC = &AUX_Q;
- assign isCounting = preset | (isCounting & ~TC);
-
- always @(Q or preset)
- begin
- casex ({preset}) // synopsys parallel_case full_case
- 'b1: // retrigger presets from TC
- begin
- D = 'h1D4275; // preset to seed
- end
- 'b0: // normal counting
- begin
- D[22:1] = Q[21:0];
- D[0] = (Q[22] ^ Q[4]) & isCounting;
- end
- endcase
- end // always
- // Auxiliary counter for detecting terminal count
- // counts 23 bits of consecutive '1's
- always @(D[0] or preset)
- begin
- casex ({D[0], preset}) // synopsys parallel_case full_case
- 'b0?, // preset counter if zero detected
- 'b?1: // retrigger presets from TC
- begin
- AUX_D = 'h14;
- end
- 'b10: // normal counting
- begin
- AUX_D[4:1] = AUX_Q[3:0];
- AUX_D[0] = (AUX_Q[4] ^ AUX_Q[1]) & isCounting;
- end
- endcase
- end // always
-
- // Shift register description
- always @(posedge clk)
- begin
- Q = D; // make into D register
- AUX_Q = AUX_D; // make into D register
- end
- endmodule // LFSR
-